//
//  CZQLoginViewController.m
//  LoveBeer
//
//  Created by 崔正强 on 17/5/4.
//  Copyright © 2017年 崔正强. All rights reserved.
//

#import "CZQLoginViewController.h"
#import "LoveBeer.pch"

@interface CZQLoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textPhoneNum;
@property (weak, nonatomic) IBOutlet UITextField *textCheckNum;
@property (weak, nonatomic) IBOutlet UIButton *logBtn;
@property (weak, nonatomic) IBOutlet UIButton *verifyBtn;

@end

@implementation CZQLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

#pragma - 初始化状态设置 -
- (void)setupUI {
    
    self.logBtn.enabled = NO;
    
    [self.logBtn.layer setMasksToBounds:YES];
    
    self.logBtn.layer.cornerRadius = 10;
    
}
- (IBAction)textEditChanged:(id)sender {
    if (self.textPhoneNum.text.length != 0 && self.textCheckNum.text.length != 0) {
        self.logBtn.enabled = YES;
        self.logBtn.backgroundColor = appColor;
    } else {
        self.logBtn.enabled = NO;
        self.logBtn.backgroundColor = [UIColor lightGrayColor];
    }
    
}
- (IBAction)actionLoginBtn:(id)sender {
    
    if (self.textCheckNum.text.length == 4) {
        [_LoginMgr logiWithPhone:self.textPhoneNum.text Verify:self.textCheckNum.text finished:^(SMSSDKUserInfo *userInfo, NSError *error) {
            if (error == nil) {
                [self customViewExampleWithImage:@"Checkmark" title:@"验证成功" View:self.view];
            } else {
                [self customViewExampleWithImage:@"loadFailed" title:@"验证失败" View:self.view];
            }
            
        }];
    }
    
}


- (IBAction)actionGetVerifyNum:(id)sender {
    
    if (self.textPhoneNum.text.length == 11) {
        [self verifyByNumber:self.textPhoneNum.text];
    } else {
        //加载MBP
        [self customViewExampleWithImage:@"loadFailed" title:@"手机号码错误" View:self.view];
    }
    
}

- (void)verifyByNumber:(NSString *)phoneNum {
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:phoneNum zone:@"86" customIdentifier:nil result:^(NSError *error) {
        
        if (error == nil) {
            [self customViewExampleWithImage:@"Checkmark" title:@"获取验证码成功" View:self.view];
            [self.navigationController popToViewController:self.navigationController.viewControllers.firstObject animated:YES];

        } else {
            [self customViewExampleWithImage:@"loadFailed" title:@"获取验证码失败" View:self.view];
        }
        
    }];
             
}




@end
